package cate.game.role;


import cate.common.table.d.GDOperation;

import java.util.HashMap;
import java.util.Map;

/** 玩家的操作日志(不持久化到数据库，临时的内存级别) */
public class OperationLog {
    /** 当前正在操作的功能 */
    private int operation;

    /** 当前正在操作的功能的子类型 */
    private int operationSub;

    public void setOperation(int operation) {
        this.operation = operation;
    }

    public void setOperation(int operation, int operationSub) {
        this.operation = operation;
        this.operationSub = operationSub;
    }

    public void setOperationSub(int operationSub){
        this.operationSub = operationSub;
    }

    public void clearOperation() {
        this.operation = GDOperation.NULL;
        this.operationSub = 0;
    }

    public int getOperation() {
        return this.operation;
    }

    public int getOperationSub() {
        return this.operationSub;
    }

    private final Map<String, Long> actionRec = new HashMap<>();
    /** 是否是正常操作 */
    public boolean isNormalAction(String actionCode, long interval) {
        Long lastTime = actionRec.getOrDefault(actionCode, 0L);
        long now = System.currentTimeMillis();
        if(now - lastTime > interval) {
            actionRec.put(actionCode, now);
            return true;
        }
        return false;
    }
}
